/**
 * Created by Administrator on 2017/8/7.
 */
$(function(){
    //后台数据
     var data={status:1,totalCounts:11,pageSize:10,visiblePages:5,currentPage:1,data:[{guid:"12344",upDate:"2017-06-13",name:"测试姓名1",personCode:"411481198903128978",admissionDate:"2017-06-04",visitingType:"住院",hospital:"天坛医院",description:"暂无"},
         {guid:"123484",upDate:"2017-06-01",name:"测试姓名2",personCode:"411481198903128978",admissionDate:"2017-04-04",visitingType:"住院",hospital:"天坛医院",description:"无"},
         {guid:"123474",upDate:"2017-05-15",name:"测试姓名2",personCode:"411481198903128978",admissionDate:"2017-04-04",visitingType:"住院",hospital:"天坛医院",description:"无"},
         {guid:"123464",upDate:"2017-05-04",name:"测试姓名2",personCode:"411481198903128978",admissionDate:"2017-04-04",visitingType:"住院",hospital:"天坛医院",description:"无"},
         {guid:"123454",upDate:"2017-04-15",name:"测试姓名2",personCode:"411481198903128978",admissionDate:"2017-04-04",visitingType:"住院",hospital:"天坛医院",description:"无"},
         {guid:"123444",upDate:"2017-04-10",name:"测试姓名2",personCode:"411481198903128978",admissionDate:"2017-04-04",visitingType:"住院",hospital:"天坛医院",description:"无"},
         {guid:"123434",upDate:"2017-04-01",name:"测试姓名2",personCode:"411481198903128978",admissionDate:"2017-04-04",visitingType:"住院",hospital:"天坛医院",description:"无"},
         {guid:"123424",upDate:"2017-03-23",name:"测试姓名2",personCode:"411481198903128978",admissionDate:"2017-04-04",visitingType:"住院",hospital:"天坛医院",description:"无"},
         {guid:"123414",upDate:"2017-03-15",name:"测试姓名2",personCode:"411481198903128978",admissionDate:"2017-04-04",visitingType:"住院",hospital:"天坛医院",description:"无"},
         {guid:"12324",upDate:"2017-03-10",name:"测试姓名2",personCode:"411481198903128978",admissionDate:"2017-04-04",visitingType:"住院",hospital:"天坛医院",description:"无"},
         {guid:"12334",upDate:"2017-02-13",name:"测试姓名3",personCode:"411481198903128978",admissionDate:"2017-02-04",visitingType:"住院",hospital:"天坛医院",description:"暂无"}
     ]};

    //获取数据渲染页面
    //var html="";
    //$.each(data.data,function(i,item){
    //    html+='<tr>';
    //    html+='<td class="tdLabel_5"><div class="imgIcon"><img src="../../publics/images/file.png" alt=""/></div></td>';
    //    html+='<td class="tdLabel_5">'+item.upDate+'</td>';
    //    html+='<td class="tdLabel_5">'+item.name+'</td>';
    //    html+='<td class="tdLabel_5">'+item.personCode+'</td>';
    //    html+='<td class="tdLabel_5">'+item.admissionDate+'</td>';
    //    html+='<td class="tdLabel_5">'+item.visitingType+'</td>';
    //    html+='<td class="tdLabel_5">'+item.hospital+'</td>';
    //    html+='<td class="tdLabel_5">'+item.description+'</td>';
    //    html+='<td class="tdLabel_5"><a href="Pigeonhole_Info1.html">绑定</a></td>';
    //});
    //$("#tableList").html(html);



    function getPage(pagenum,pagesize){
        $.ajax({
            type:"get",
            url:"",
            data:{page:pagenum,pagesize:pagesize},
            success:function(result){
                var data=result.data;
                var totalPages = Math.ceil(data.totalCounts/data.pageSize);
                $('#page_plus').jqPaginator({
                    totalCounts: data.totalCounts,
                    pageSize:data.pageSize,
                    visiblePages: data.visiblePages,
                    currentPage: data.currentPage,
                    first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
                    prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
                    next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
                    last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
                    page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
                    onPageChange: function (num,type) {

                        if(type !='init'){
                            //alert(type+'当前第' + num + '页');
                            //var datajson=data.data.slice((num-1)*data.pageSize,num*data.pageSize+1);
                            //page(num,data.pageSize,datajson);
                            getPage(num,pagesize)
                        }
                        $("#totalPage").html(data.totalCounts);
                        $("#currentPage").html(num+"/"+totalPages);
                    }
                });
            }
        })
    }
    //列表渲染
    //page(data.currentPage,data.pageSize,data.data)
    ////分页渲染
    //var totalPages = Math.ceil(data.totalCounts/data.pageSize);
    //$('#page_plus').jqPaginator({
    //    totalCounts: data.totalCounts,
    //    pageSize:data.pageSize,
    //    visiblePages: data.visiblePages,
    //    currentPage: data.currentPage,
    //
    //    first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
    //    prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
    //    next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
    //    last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
    //    page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
    //    onPageChange: function (num,type) {
    //
    //        if(type !='init'){
    //            //alert(type+'当前第' + num + '页');
    //            var datajson=data.data.slice((num-1)*data.pageSize,num*data.pageSize+1);
    //            page(num,data.pageSize,datajson);
    //        }
    //        $("#totalPage").html(data.totalCounts);
    //        $("#currentPage").html(num+"/"+totalPages);
    //    }
    //});
})

//function page(page,pageSize,data){
//    var html="";
//    $.each(data,function(i,item){
//        if(i>=pageSize){
//            return false;
//        }
//        html+='<tr data-guid="'+item.guid+'">';
//        html+='<td class="tdLabel_5"><div class="imgIcon"><img src="../../publics/images/file.png" alt=""/></div></td>';
//        html+='<td class="tdLabel_5">'+item.upDate+'</td>';
//        html+='<td class="tdLabel_5">'+item.name+'</td>';
//        html+='<td class="tdLabel_5">'+item.personCode+'</td>';
//        html+='<td class="tdLabel_5">'+item.admissionDate+'</td>';
//        html+='<td class="tdLabel_5">'+item.visitingType+'</td>';
//        html+='<td class="tdLabel_5">'+item.hospital+'</td>';
//        html+='<td class="tdLabel_5">'+item.description+'</td>';
//        html+='<td class="tdLabel_5"><a href="Pigeonhole_Info1.html">绑定</a></td>';
//    });
//
//    $("#tableList").html(html);
//}